package com.zzyl.nursing.controller;

import java.util.List;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.NursingTaskCancelDto;
import com.zzyl.nursing.dto.NursingTaskDoDto;
import com.zzyl.nursing.dto.NursingTaskUpdateTimeDto;
import com.zzyl.nursing.vo.NursingTaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理任务Controller
 *
 * @author alexis
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/nursing/task")
@Api(tags = "护理任务管理")
public class NursingTaskController extends BaseController {
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 查询护理任务列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取护理任务列表")
    public TableDataInfo<List<NursingTask>> list(@ApiParam(value = "护理任务查询条件") NursingTask nursingTask) {
        startPage();
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(nursingTask);
        return getDataTable(list);
    }

    /**
     * 取消护理任务
     */
    @ApiOperation("取消护理任务")
    @PreAuthorize("@ss.hasPermi('nursing:task:cancel')")
    @PutMapping("/cancel")
    public AjaxResult cancel(@ApiParam("护理任务信息") @RequestBody NursingTaskCancelDto nursingTaskCancelDto) {
        return toAjax(nursingTaskService.cancel(nursingTaskCancelDto));
    }

    /**
     * 执行任务
     */
    @ApiOperation("执行任务")
    @PreAuthorize("@ss.hasPermi('nursing:task:do')")
    @PutMapping("/do")
    public AjaxResult doTask(@ApiParam("护理任务ID") @RequestBody NursingTaskDoDto nursingTaskDoDto) {
        return toAjax(nursingTaskService.doTask(nursingTaskDoDto));
    }

    /**
     * 任务改期
     */
    @ApiOperation("任务改期")
    @PreAuthorize("@ss.hasPermi('nursing:task:change')")
    @PutMapping("/updateTime")
    public AjaxResult change(@ApiParam("护理任务ID") @RequestBody NursingTaskUpdateTimeDto nursingTaskUpdateTimeDto) {
        return toAjax(nursingTaskService.updateTime(nursingTaskUpdateTimeDto));
    }

    /**
     * 获取护理任务详细信息
     */
    @GetMapping("/{id}")
    @ApiOperation("获取护理任务详细信息")
    public R<NursingTaskVo> getInfo(@ApiParam(value = "护理任务ID", required = true) @PathVariable("id") Long id)
    {
        return R.ok(nursingTaskService.selectNursingTaskById(id));
    }

}
